﻿@model IEnumerable<WebVideo.EntityChat>
@{
    ViewBag.Title = "Danh sách tin nhắn";
}
<div class="inner-container" id="inner-container" style="width: 8000px">
    <div class="wrap-widget">
        <div class="inner-widget _7">
            <h1>Danh sách tin nhắn</h1>

            <div class="widget _2x3 phone bg-color-MediumSeaGreen">
                <div class="widget-content">
                    @Html.Action("Index", "Individual", new { Friend = Request.Cookies["UserId"].Value })
                </div>
                <!--/ .widget-content-->
            </div>
            <!--/ .widget-->

            <div class="widget _2x3  bg-color-cadetblue phone">
                <div class="widget-content contScroll listMsg" >
                    <div class="hdMsg">
                        <a href="#" style="color: white;">Danh sách bạn bè</a>
                       @* <a href="#" class="btn btn-small pull-right btn-danger" onclick="return AllFriend()">Xem &nbsp;|&nbsp;<i class="icon-ok icon-white"></i></a>*@
                    </div>
                    <div id="AllFriend">
                    @Html.Action("_ListAllFriend", "Individual")
                     </div>

                </div>
                <!--/ .widget-content contScroll listMsg-->
            </div>
            <!--/ .widget _2x3  bg-color-cadetblue phone-->


            <div class="widget _3x3 phone bg-color-blueLight">
                <div class="hdMsg">

                    <a href="#" class="title" id="FiendChat">@ViewBag.FriendChat</a>
                    <a href="#" class="btn btn-small pull-right btn-danger" onclick="return ChatDelete()">Xóa &nbsp;|&nbsp;<i class="icon-remove icon-white"></i></a>
                </div>
                <!--/ hdMsg-->

                <div class="widget-content contScroll detailMsg" id="ContentChat">

                    @{
                        foreach (var item in Model)
                        {
                            if (item.UserName != Request.Cookies["UserId"].Value)
                            {
                        <div class="media">
                            <div class="pull-left" style="width: 34px;">
                                <img class="media-object" src="/Content/Images/Avatar/@item.EntityUser.Avatar" alt="" style="width: 34px; height: 34px;" />
                            </div>
                            <div class="media-body">
                                <h5 class="media-heading">@item.UserName</h5>
                                @item.Contents
                            </div>
                        </div>
                            }
                            else
                            {
                        <div class="media">
                            <div class="pull-left" style="width: 34px;">
                                <img class="media-object" src="/Content/Images/Avatar/@Request.Cookies["UserAvatar"].Value" alt="" style="width: 34px; height: 34px;" />
                            </div>
                            <div class="media-body">
                                <h5 class="media-heading">@item.UserName</h5>
                                @item.Contents
                            </div>
                        </div>
                            }
                        }
                    }

                </div>
                <!--/ .widget-content contScroll detailMsg-->

                <div class="inputMsg">
                    <div class="row-fluid">
                        <div class="span10">
                            <div class="row-fluid">
                                <input type="text" class="span12" placeholder="Nhập tin nhắn..." id="ChatReply" onkeypress="return Chat(event);" />
                            </div>
                        </div>
                        @* <div class="span2">
                            <div class="row-fluid">
                                <button class="btn btn-small btn-success span12" onkeypress="return Chat(event);">Send</button>
                            </div>
                        </div>*@
                    </div>
                </div>
                <!--/ .inputMsg-->

            </div>
            <!--/ .widget _3x3 phone bg-color-blueLight-->


        </div>
        <!--/ .inner-widget-->
    </div>
    <!--/ .wrap-widget -->
</div>
<!--/ .inner-container-->
</div>
@section occasionalScripts {
    <script type="text/javascript" src="@Url.Content("~/Content/cssFrontEnd/js/jquery.min.js")" ></script>
    <script type="text/javascript" src="@Url.Content("~/Content/cssFrontEnd/js/load.js")" ></script>
    <script type="text/javascript" src="@Url.Content("~/Content/cssFrontEnd/js/styles.js")" ></script>
    <script type="text/javascript" src="@Url.Content("~/Content/cssFrontEnd/js/jquery.nicescroll.min.js")" ></script>
}
<script type="text/javascript">
    document.body.className = 'no-js';
    // xóa nội dung chat
    $(document).ready(function () {
        $('li#TaiKhoanCuaBan').addClass('active');
    });
    function ChatDelete() {
        var UserName = $("a#FiendChat").text();
        if (UserName == "" || UserName == null) {
        }
        else {
            var getURL = '@Url.Action("_ContentChat", "Individual")';
            $.get(getURL, { "FriendChat": "", "Content": "", "Delete": UserName }, function (data) {
                $("div#ContentChat").html("<div>Không có nội dung</div>");
            });
        }
    }

    // chat
    function Chat(e) {
        var UserName = $("a#FiendChat").text();
        var Content = $("input#ChatReply").val();

        var Delete = "";

        var key;
        if (window.event)
            key = window.event.keyCode;     //IE 
        else
            key = e.which;
        if (key == 13) {
            $("input#ChatReply").val("");
            if (UserName == "" || UserName == null) {
            }
            else {
                var dem = 0;

                var demthoigian = function () {
                    if (dem > 0) {
                        Content = "";
                        Delete = UserName;

                    }
                    var getURL = '/Individual/_ContentChat';
                    $.get(getURL, { "FriendChat": UserName, "Content": Content, "Delete": UserName }, function (data) {
                        $("div#ContentChat").html(data);
                    });
                    setTimeout(demthoigian, 5000); //5s
                    dem = dem + 1;
                };
                demthoigian();
            }

        }
    }
    // hiển thị danh sách bạn mới chat
    function ChatContent(UserName) {
        if (UserName != "") {
            $("a#FiendChat").text(UserName);
            var getURL = '@Url.Action("_ContentChat", "Individual")';
            $.get(getURL, { "FriendChat": UserName, "Content": "", "Delete": "" }, function (data) {
                $("div#ContentChat").html(data);
            });
        }
    }
    // hiển thị toàn bộ danh sách bạn

  @*  function AllFriend() {
        var getURL = '@Url.Action("_ListFriendChat", "Individual")';
        $.get(getURL, function (data) {
            $("div#AllFriend").html(data);
        });
    }*@

</script>


